perm filename APR2L.FAI[REV,MUS] blob sn#350997 filedate 1978-04-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	TITLE APR2 - Second-order all-pass reverberator, lattice form
C00005 00003	AC's
C00007 00004	Loop:
C00008 ENDMK
C⊗;
TITLE APR2 - Second-order all-pass reverberator, lattice form

ENTRY APR2
INTERNAL APR2

COMMENT ⊗
EXTERNAL PROCEDURE APR2(REFERENCE REAL IN, OUT; INTEGER n;
	REFERENCE REAL MEM1, MEM2; INTEGER delay;
	REAL gain1, gain2; REFERENCE INTEGER pos);
Remarks:  Reverberates the samples in the input buffer "IN" into the
    output buffer "OUT", using the 2nd order all-pass reverberator
    described by "gain1", "gain2", and "delay".  Delay line used is "MEM".
    For first call, "pos" should be set to 0 and "MEM" array should be
    filled with 0's.  On subsequent calls for the same input stream, the
    same "MEM" array and "pos" should be used (and not cleared to 0).
    The "IN" and "OUT" buffers may be the same array.  The buffer length
    "n" may even be 1, although that would be very inefficient.

Ex.:
DEFINE N=1000;
REAL ARRAY InStream,OutStream[1:N];
DEFINE Delay=23;
REAL ARRAY DelayMemory1,DelayMemory2[1:Delay];
INTEGER SavedPointer;

Comment		First call:
	... fill InStream with samples here ...;
ARRCLR(DelayMemory1);
ARRCLR(DelayMemory2);
APR2(InStream[1],OutStream[1],N,DelayMemory1[1],DelayMemory2[1],Delay,
	0.707,0.75,SavedPointer ← 0);
Comment		Subsequent calls:;
	... process OutStream samples here ...
	... fill InStream again here ...
APR2(InStream[1],OutStream[1],N,DelayMemory1[1],DelayMemory2[1],Delay,
	0.707,0.75,SavedPointer);

⊗;

;AC's
p←←17;		Usual PDL pointer
t←←0;		Temporary
t1←←1;		Likewise
i←←2;		Index for Input and Output arrays
j←←3;		Index for Delay memory

DEFINE refPOS <-1(p)>;	"Index" of current position in delay memory
DEFINE GAIN.2 <-2(p)>;	Gain of attenuation loop, 2nd order
DEFINE GAIN.1 <-3(p)>;	Gain of attenuation loop, 1st order
DEFINE DELAY <-4(p)>;	Number of samples of delay in loop
DEFINE refM.2 <-5(p)>;	Address of first word of delay memory array 2
DEFINE refM.1 <-6(p)>;	Address of first word of delay memory array 1
DEFINE N <-7(p)>;	Length of input and output buffers
DEFINE refOUT <-10(p)>;	Address of first word of output buffer array
DEFINE refIN <-11(p)>;	Address of first word of input buffer array
DEFINE nARGS <11>;
DEFINE SUBRET <
	SUB	p,[nARGS+1,,nARGS+1]
	JRST	@nARGS+1(p)
>

Apr2:	MOVE	t,refIN
	HRRM	t,In1
	HRRM	t,In2
	MOVE	t,refOUT
	HRRM	t,Out1
	MOVE	t,refM.1
	HRRM	t,Mem1.1
	HRRM	t,Mem2.1
	HRRM	t,Mem3.1
	MOVE	t,refM.2
	HRRM	t,Mem1.2
	HRRM	t,Mem2.2
	HRRM	t,Mem3.2
	MOVE	t,GAIN.1
	HLRM	t,Gain11
	MOVE	t,GAIN.2
	HLRM	t,Gain12
	MOVN	t,DELAY
	HRRM	t,Delay1
	SKIPN	j,@refPOS
	HRLZ	j,t
	MOVN	i,N
	HRLZ	i,i

Loop:
Mem1.1:	MOVE	t,(j);refM.1
In1:	FSBR	t,(i);refIN
Gain11:	FMPRI	t,;GAIN.1
Mem2.1:	FADRM	t,(j);refM.1
In2:	FADR	t,(i);refIN
Mem1.2:	MOVE	t1,(j);refM.2
	FSBR	t1,t
Gain12:	FMPRI	t1,;GAIN.2
Mem2.2:	FADRM	t1,(j);refM.2
	FADR	t1,t
Mem3.2:	EXCH	t1,(j);refM.2
Mem3.1:	EXCH	t1,(j);refM.1
Out1:	MOVEM	t1,(i);refOUT
	AOBJN	j,Testi
Delay1:	HRLZI	j,;DELAY
Testi:	AOBJN	i,Loop

	MOVEM	j,@refPOS
	SUBRET

	END